const { RandomForest } = require('random-forest');

// 准备数据集
const data = [
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], // 0
  [2, 2, 3, 4, 5, 6, 7, 8, 9, 10], // 1
  [1, 2, 2, 4, 5, 6, 7, 8, 9, 10], // 2
  [1, 2, 2, 4, 5, 6, 7, 8, 9, 10], // 2
  [1, 2, 2, 4, 5, 6, 7, 8, 9, 10], // 2
  [1, 2, 2, 4, 5, 6, 7, 8, 9, 10], // 2
  [1, 2, 2, 4, 5, 6, 7, 8, 9, 10], // 2
  [1, 2, 2, 4, 5, 6, 7, 8, 9, 10], // 2
  [1, 2, 2, 4, 5, 6, 7, 8, 9, 10], // 2
  [1, 2, 3, 4, 5, 6, 7, 8, 9, 9], // 9
];

// 划分数据集
const trainData = data.slice(0, 8);
const testData = data.slice(8);

// 训练模型
const rf = new RandomForest();
rf.train(trainData);

// 预测结果
const predictions = testData.map((sequence) => {
  const probabilities = rf.predict(sequence);
  return probabilities.indexOf(Math.max(...probabilities));
});

// 输出结果
const answer = predictions
  .reduce((acc, cur) => {
    if (acc.indexOf(cur) === -1) {
      acc.push(cur);
    }
    return acc;
  }, [])
  .slice(0, 6);
console.log(answer);
